package com.top145;

public class Solution36 {
    public boolean isValidSudoku(char[][] board) {
        int[][] row = new int[9][10];
        int[][] col = new int[9][10];
        int[][] matrix = new int[9][10];
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[0].length; j++) {
                if (board[i][j] == '.') continue;
                if (row[i][board[i][j] - '0'] == 1) return false;
                if (col[j][board[i][j] - '0'] == 1) return false;
                if (matrix[3 * (i / 3) + j / 3][board[i][j] - '0'] == 1) return false;
                row[i][board[i][j] - '0'] = 1;
                col[j][board[i][j] - '0'] = 1;
                matrix[3 * (i / 3) + j / 3][board[i][j] - '0'] = 1;
            }
        }
        return true;
    }
}
